<?php /*a:1:{s:53:"/www/wwwroot/cmf_job/87/app/admin/view/main/user.html";i:1699869064;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户管理</title>
    <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <!--搜索区域-->
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索信息：</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input name="search" class="layui-input" placeholder="输入 ID/账号/卡密/支付宝/姓名"/>
                        </div>
                    </div>
                    <div class="layui-inline">&emsp;
                        <button class="layui-btn icon-btn" lay-filter="TbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                    <!--搜索区域结束-->
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="Table" lay-filter="Table"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="TbBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--添加 编辑 Model-->
<script type="text/html" id="AddEditModel">
    <form id="AddEditForm" lay-filter="AddEditForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="row">
            <div class="layui-col-md6">
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称:</label>
                    <div class="layui-input-block">
                        <input name="nickname" placeholder="请输入账号" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">账号:</label>
                    <div class="layui-input-block">
                        <input name="username" placeholder="请输入账号" class="layui-input"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">密码:</label>
                    <div class="layui-input-block">
                        <input name="password" placeholder="请输入密码" class="layui-input"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支付宝账号:</label>
                    <div class="layui-input-block">
                        <input name="alipay" placeholder="请输入支付宝账号" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支付宝姓名:</label>
                    <div class="layui-input-block">
                        <input name="name" placeholder="请输入支付宝姓名" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机:</label>
                    <div class="layui-input-block">
                        <input name="tel" placeholder="请输入手机" class="layui-input"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">余额:</label>
                    <div class="layui-input-block">
                        <input name="balance" placeholder="请输入余额" class="layui-input"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6">
                <div class="layui-form-item">
                    <label class="layui-form-label">微信:</label>
                    <div class="layui-input-block">
                        <input name="wechat" placeholder="请输入微信" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注:</label>
                    <div class="layui-input-block">
                        <input name="remarks" placeholder="请输入备注 " class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">卡密:</label>
                    <div class="layui-input-block">
                        <input name="cdkey" placeholder="请输入备注 " class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">到期时间:</label>
                    <div class="layui-input-block">
                        <input name="out_time" id="out_time" placeholder="请输入到期时间" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">会员</label>
                    <div class="layui-input-block">
                        <input type="radio" name="vip" value="0" title="普通用户" checked>
                        <input type="radio" name="vip" value="1" title="VIP用户">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上级:</label>
                    <div class="layui-input-block">
                        <input name="invite" placeholder="上级" class="layui-input"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="AddEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>
<!-- js部分 -->
<script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/static/assets/js/common.js?v=318"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;

        /* 渲染表格 */
        var insTb = table.render({
            elem: '#Table',
            url: "<?php echo url('admin/main/userList'); ?>",
            page: true,
            limit: 90,
            toolbar: ['<p>',
                '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
                '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
                '</p>'].join(''),
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                // 表格字段开始
                {type: 'numbers'},
                {field: 'id', title: 'ID', width: 80},
                {field: 'remarks', title: '备注'},
                {field: 'username', title: '账号'},
                {field: 'vip', title: 'Vip',width: 100,templet: function (d){
                    if(d.vip === 1){
                        return '<span class="text-danger">VIP</span>'
                    }else{
                        return '<span class="">普通</span>'
                    }

                    }},
                {field: 'alipay', title: '支付宝账号'},
                {field: 'name', title: '支付宝名字'},
                {field: 'tel', title: '手机'},
                {field: 'total', title: '总提现'},
                {field: 'balance', title: '余额'},
                {field: 'cdkey', title: '卡密'},
                {field: 'reg_time', title: '注册时间', width: 160},
                {field: 'out_time', title: '到期时间', width: 160},
                {field: 'status', title: '状态', width: 160,templet:function(d){
                    //根据状态返回按钮
                        if(d.status=='正常')
                        {
                            return '<span class="layui-btn layui-btn-primary layui-btn-xs ">'+d.status+'</span><button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="status">禁用</button>';
                        }else{
                            return '<span class="layui-btn layui-btn-primary layui-btn-xs">'+d.status+'</span><button class="layui-btn layui-btn-xs layui-btn-green" lay-event="status">启用</button>';
                        }
                    }},
                {title: '操作', toolbar: '#TbBar', align: 'center', width: 120}
            ]]
        });

        /* 表格搜索 */
        form.on('submit(TbSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });

        /* 表格工具条点击事件 */
        table.on('tool(Table)', function (obj) {
            if (obj.event === 'edit') { // 修改
                showEditModel(obj.data)
            } else if (obj.event === 'del') { // 删除
                doDel(obj);
            }else if(obj.event === 'status'){
                var data = obj.data;
                var status = data.status;
                var id = data.id;
                console.log(status)

                if(status=='正常')
                {
                    layer.confirm('确定要禁用该用户吗？', {
                        skin: 'layui-layer-admin',
                        shade: .1,
                    }, function (i) {
                        layer.close(i);
                        var loadIndex = layer.load(2);
                        $.get("<?php echo url('admin/main/userStatus'); ?>", {
                            id: id,
                            status: '禁用'
                        }, function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                    });
                }else{
                    layer.confirm('确定要启用该用户吗？', {
                        skin: 'layui-layer-admin',
                        shade: .1,
                    }, function (i) {
                        layer.close(i);
                        var loadIndex = layer.load(2);
                        $.get("<?php echo url('admin/main/userStatus'); ?>", {
                            id: id,
                            status: '正常'
                        }, function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                    });
                }
            }
        });

        /* 表格头工具栏点击事件 */
        table.on('toolbar(Table)', function (obj) {
            if (obj.event === 'add') { // 添加
                showEditModel()
            } else if (obj.event === 'del') { // 删除
                var checkRows = table.checkStatus('Table');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.id;
                });
                doDel({ids: ids});
            }
        });

        /* 删除 */
        function doDel(obj) {
            layer.confirm('确定要删除选中数据吗？', {
                skin: 'layui-layer-admin',
                shade: .1,
            }, function (i) {
                layer.close(i);
                var loadIndex = layer.load(2);
                $.get("<?php echo url('admin/main/userDel'); ?>", {
                    id: obj.data ? obj.data.id : '',
                    ids: obj.ids ? obj.ids.join(',') : ''
                }, function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }


        function showEditModel(mData) {
            admin.open({
                type: 1,
                title: (mData ? '修改' : '添加') + '用户',
                content: $('#AddEditModel').html(),
                area: '700px',
                offset: 'auto',
                success: function (layero, dIndex) {
                    laydate.render({
                        elem: '#out_time',
                        type: 'datetime'
                    });
                    // 回显表单数据
                    form.val('AddEditForm', mData);
                    // 表单提交事件
                    form.on('submit(AddEditSubmit)', function (data) {
                        var loadIndex = layer.load(2);
                        let url = mData ? "<?php echo url('admin/main/userEdit'); ?>" : "<?php echo url('admin/main/userAdd'); ?>";
                        $.post(url, data.field, function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200) {
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                        return false;
                    });
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                }
            });
        }
    });
</script>
</body>
</html>
